// 引入axios
import axios from 'axios'
export default {
    search({commit},searchName){
        // 更新状态变为请求中
        commit('REQUESTING')
        // 发送异步收索请求
        axios.get(`https://api.github.com/search/users?q=${searchName}`)
        .then(response=>{
            const data = response.data;
            const users = data.items.map(item=>({
                userName:item.login,
                url:item.html_url,
                avatar_url:item.avatar_url,
            }))
            commit('REQ_SUCCESS',users)
          })
          .catch(error=>{
            commit('REQ_ERRORMSG',{errorMsg:error.message})
          })  
      }
}